import 'package:flutter/material.dart';

class SwitchDemo extends StatefulWidget {
  SwitchDemo({Key key}) : super(key: key);

  @override
  _SwitchDemoState createState() => _SwitchDemoState();
}

class _SwitchDemoState extends State<SwitchDemo> {

  // 按钮选中状态
  bool _currentSwitchValue = true;

  bool _currentSwitchValue2 = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("SwitchDemo"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SwitchListTile(
              value: _currentSwitchValue2, 
              onChanged: (value) {
                setState(() {
                  _currentSwitchValue2 = value;
                });
              },
              title: Text("Switch Item A"),
              subtitle: Text("Description"),
              secondary: Icon(Icons.switch_account),
              selected: _currentSwitchValue2,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Switch(
                  value: _currentSwitchValue, 
                  onChanged: (value) {
                    setState(() {
                      _currentSwitchValue = value;
                    });
                  },
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}